/** Description of Stats.java 
 * @version 1.0
 *
 * @author panther
 * Jayant Pratim Saikia
 * jay.saikia@gmail.com
 *
 */
package com.panther.awp.android.smoker.activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.panther.awp.android.smoker.R;
import com.panther.awp.android.smoker.activities.graphs.GraphBrand;
import com.panther.awp.android.smoker.activities.graphs.GraphLastTwoWeeks;
import com.panther.awp.android.smoker.activities.graphs.GraphToday;
import com.panther.awp.android.smoker.activities.graphs.GraphWeek;

public class Stats extends ListActivity {
	private ListView lv;
	private Intent mIntent;
	private static final String mHighlight = "highlight";
	private static final String mDescription = "description";
	private final int INFO_DIALOG = 1001;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.statstab);
        lv = getListView();
        populateData();
    }

	private void populateData() {
		List<HashMap<String, String>> listHMap = new ArrayList<HashMap<String,String>>();
		listHMap = getTheStaticListOfGraphs();
		String[] from = new String[] {mHighlight, mDescription};
		int[] to = new int[] {R.id.STATS, R.id.DESC};
		SimpleAdapter adapter = new SimpleAdapter(this, listHMap, R.layout.statsrow, from, to);
		lv.setAdapter(adapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		switch (position) {
		case 0:
			//Start intent and show for 1st stat
			mIntent = new Intent(this, GraphBrand.class);
			break;
		case 1:
			//Start intent and show for 2nd stat
			mIntent = new Intent(this, GraphToday.class);
			break;
		case 2:
			//Start intent and show for 3rd stat
			mIntent = new Intent(this, GraphWeek.class);
			break;
		case 3: 
			//Start intent and show for 4th stat
			mIntent = new Intent(this, GraphLastTwoWeeks.class);
			break;
		}
		startActivity(mIntent);
	}
	
	private List<HashMap<String, String>> getTheStaticListOfGraphs() {
		//String[] mStrings = new String[] { "Brands", "Today", "This Week", "This Month", "This Year" };
		List<HashMap<String, String>> listHMap = new ArrayList<HashMap<String,String>>();
		
		HashMap<String, String> tempMap0 = new HashMap<String, String>();
		tempMap0.put(mHighlight, "Brands");
		tempMap0.put(mDescription, "Cigarettes smoked of each brand");
		listHMap.add(tempMap0);
		
		HashMap<String, String> tempMap1 = new HashMap<String, String>();
		tempMap1.put(mHighlight, "Today");
		tempMap1.put(mDescription, "Cigarettes smoked today");
		listHMap.add(tempMap1);
		
		HashMap<String, String> tempMap2 = new HashMap<String, String>();
		tempMap2.put(mHighlight, "This Week");
		tempMap2.put(mDescription, "Smoking habits this week");
		listHMap.add(tempMap2);
		
		HashMap<String, String> tempMap3 = new HashMap<String, String>();
		tempMap3.put(mHighlight, "Last Two Weeks");
		tempMap3.put(mDescription, "This week and last weeks statistics");
		listHMap.add(tempMap3);
		
		/*HashMap<String, String> tempMap4 = new HashMap<String, String>();
		tempMap4.put("highlight", "This Year");
		tempMap4.put("description", "Smoking habits this year");
		listHMap.add(tempMap4);
		
		HashMap<String, String> tempMap5 = new HashMap<String, String>();
		tempMap5.put("highlight", "Brands");
		tempMap5.put("description", "Test");
		listHMap.add(tempMap5);
		
		HashMap<String, String> tempMap6 = new HashMap<String, String>();
		tempMap6.put("highlight", "Brands");
		tempMap6.put("description", "Test");
		listHMap.add(tempMap6);
		
		HashMap<String, String> tempMap7 = new HashMap<String, String>();
		tempMap7.put("highlight", "Brands");
		tempMap7.put("description", "Test");
		listHMap.add(tempMap7);
		
		HashMap<String, String> tempMap8 = new HashMap<String, String>();
		tempMap8.put("highlight", "Brands");
		tempMap8.put("description", "Test");
		listHMap.add(tempMap8);*/
		
		return listHMap;
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.smoketabmenu, menu);
	    return true;

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		  case R.id.settings_menuItem:
					Intent intent = new Intent(this, Settings.class);
					startActivity(intent);
					return super.onOptionsItemSelected(item);
		  case R.id.info_menuItem:
				  showDialog(INFO_DIALOG);
		  default:
			  		return super.onOptionsItemSelected(item);
		  }
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		AlertDialog.Builder builder;
		AlertDialog alertDialog;
		Context mContext = Stats.this;
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
		switch (id) {
			case INFO_DIALOG:
				View layout = inflater.inflate(R.layout.info_dialog, (ViewGroup) findViewById(R.id.info_dialog_id));
				builder = new AlertDialog.Builder(mContext);
				builder.setView(layout);
				alertDialog = builder.create();
				alertDialog.setTitle("Smoker App");
				break;
			default:
				alertDialog = null;
		}
		return alertDialog;
	}
}
